﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace suanpan.API.Components.Core
{
    public static class DateTimeExtensions
    {
        public static int Epoch(this DateTime d)
        {
            return (int)(d.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds;
        }
        public static DateTime FromEpoch(int epoch)
        {

            DateTime d = new DateTime(1970, 1, 1);
            d = d.AddSeconds(epoch);
            return d;

        }
        public static int UtcNowEpoch()
        {
            return DateTime.UtcNow.Epoch();
        }
    }
}
